package dataTypes;

public class DatatypesPractise {
	
	//Primitive datatypes in java are
	int i ; //32 bits
	char c; //Char in java is 16 bits to support internationalization
	short s; //  short is 16 bits
	long l; //long is 64 bits
	float f ; // 32 bits 
	double d ; // 64 bits
	boolean b ; // boolean takes only 2 values
	byte bt ; // byte is  8 bits
	
	String str ; //string is not primitive data type
	
	//ordering of data types
	//byte , short , int , long , float , double
	//                     char
	public DatatypesPractise()
	{
		
		//Widening is LHS datatype > RHS datatype
		//Java compiler has no issues with this
		//Except whhen we try to assign float to long
		
		//example
		int i = 20 ;
		long l = i ; //widening 
		
		
		
		//Narrowing happens when 3 conditions are satisfies 
		//1. Lhs datatype should be char , byte , short 
		//2. RHS datatype should be one of char ,byte, short and int 
		//3. java compiler should be should that sourceis within the range of the destination value
		//i.e at compile time
		
		//Narrowing is implicit only for those 4 datatypes if they satisfy above 3 conditions and it is explicit 
		//for long, double ,float because these datatypes are handled by FPU instructions where as other datatypes are 
		//handled by cpu instructions
		
//		int d = 20 ; //if we do not mention final then it will throw an error at short s=d
						// because at compile time javav only know tht d is int and tht is greater thn short
		final int d = 20 ;
		short s = d ;
		
		
		
		
		//explicit narrowing or typecasting
		
		long l2 = 30 ;
		double d2 = (double)l2 ;
		
		
	}

}
